<template>
  <div class="detail-nav-bar">
    <nav-bar class="nav-bar">
      <div class="left" slot="left" @click="backClick">
        <img src="~assets/img/common/back.svg" alt="" />
      </div>
      <div slot="center">
        <span
          v-for="(item, index) in titles"
          :key="item.index"
          :class="{ active: currentIndex === index }"
          @click="itemClick(index)"
          >{{ item }}</span
        >
      </div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar.vue";

export default {
  components: { NavBar },
  name: "DetailNavBar",

  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      isActive: false,
      currentIndex: 0,
    };
  },
  methods: {
    itemClick(index) {
      this.currentIndex = index;
      this.$emit("itemClick", index);
    },
    backClick() {
      this.$router.back();
    },
  },
};
</script>

<style  scoped>
.detail-nav-bar {
  background-color: #f6f6f6;
}
.left {
  position: relative;
}

.left img {
  position: absolute;
  top: 50%;
  transform: translate(75%, 50%);
}

.center span {
  color: black;
  padding-left: 10px;
  padding-right: 10px;
}

.center .active {
  color: #ff5777;
}
</style>
